home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ROADS15.ARJ / INITW.C < prev    next >
C/C++ Source or Header  |  1993-12-23  |  5KB  |  154 lines

  1. #define INITW_C
  2.  
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include "roads.h"
  6. #include "tiles.h"
  7.  
  8. extern int view_x, view_y;   /* VIEW AREA (UPPER LEFT CORNER) */
  9. extern int viewpage;         /* CURRENTLY VIEWED PAGE */
  10. extern int startup_vmode;    /* VIDEO MODE STARTUP SETTINGS, -1 IF NOT INIT */
  11.  
  12. int far *topography;      /* BACKGROUND TILE LIST (ARRAY) */
  13. int far *terrain;      /* FOREGROUND TILE LIST (ARRAY) */
  14. int world_type=75;      /* TENDENCY TO GRASS */
  15. int edgemode=1;         /* BLOCKY GRASS/DIRT OR EDGED? */
  16. extern int frogmode;
  17.  
  18. /*
  19.  *
  20.  * Loads the world foreground tile list with roads.
  21.  *
  22.  */
  23. void init_foreground(void)
  24. {
  25.     register int x, tile, fails;
  26.  
  27.         /* INITIALIZE FOREGROUND */
  28.     for (x=0; x<WORLD_TILES_TOTAL; x++)
  29.         terrain[x]=EMPTY_TILE; /* FILL WITH EMPTY TILES */
  30.  
  31.     create_roads (); /* LAY DOWN SOME ROADS */
  32.  
  33.         /* ADD RANDOM TERRAIN */
  34.     for (x=0; x<random(MAX_TERRAIN-MIN_TERRAIN)+MIN_TERRAIN; x++)
  35.     {
  36.         fails=0;
  37.  
  38.             /* ATTEMPT TO PLACE TERRAIN -- QUIT ON EXCESSIVE FAILURE */
  39.         do {
  40.             tile=random(WORLD_TILES_TOTAL);
  41.             fails++;
  42.         } while (terrain[tile]!=EMPTY_TILE && fails<MAX_FAILS);
  43.  
  44.         if (fails<MAX_FAILS)
  45.         {
  46.             switch (random(12)+1)
  47.             {
  48.                 case 1: terrain[tile]=OBJ_SIGN;     break;
  49.                 case 2: terrain[tile]=OBJ_FIRST_GEM+random(OBJ_TOTAL_GEM); break;
  50.                 case 3: terrain[tile]=ANM_URANIUM;  break;
  51.                 case 4:
  52.                 case 5: terrain[tile]=ANM_FIRE;     break;
  53.                 case 6: if (random(100)<50) terrain[tile]=ANM_WATER1;
  54.                         else terrain[tile]=ANM_WATER2;  break;
  55.                 case 7: terrain[tile]=OBJ_ROCK1;    break;
  56.                 case 8: terrain[tile]=OBJ_ROCK2;    break;
  57.                 case 9: terrain[tile]=OBJ_ROCK3;    break;
  58.                 case 10:
  59.                 case 11:
  60.                 case 12: terrain[tile]=OBJ_BUSHES;  break;
  61.             }
  62.         }
  63.  
  64.         else break;
  65.     }
  66.  
  67.     frogmode=3;
  68. }
  69.  
  70. /*
  71.  *
  72.  * Loads the world background tile list with grassy tiles.
  73.  *
  74.  */
  75. void init_background(void)
  76. {
  77.     register int x, y, landtype_left, landtype_up, landtype_here;
  78.  
  79.         /* INITIALIZE BACKGROUND BY RANDOMLY PICKING TILES */
  80.  
  81.     /* DO FIRST TILE */
  82.     topography[0]=random(NUM_LAND_TILES)+FIRST_LAND_TILE;
  83.  
  84.     /* DO FIRST ROW */
  85.     for (x=1; x<WORLD_WIDTH; x++)
  86.     {
  87.         landtype_left=isdirt(topography[x-1]);
  88.         landtype_here=landtype_left;
  89.         if (random(100)>=CHANCE_LAND_GROUPING) /* NO GROUPING */
  90.         {
  91.             if (random(100)>=world_type) landtype_here=1;
  92.             else landtype_here=0;
  93.         }
  94.  
  95.         if (landtype_here==0) topography[x]=
  96.             random (NUM_GRASS_TILES)+FIRST_GRASS_TILE;   /* GRASS */
  97.         else topography[x]=
  98.             random (NUM_DIRT_TILES)+FIRST_DIRT_TILE;     /* DIRT */
  99.     }
  100.  
  101.     /* DO FIRST COLUMN */
  102.     for (y=1; y<WORLD_HEIGHT; y++)
  103.     {
  104.         landtype_up=isdirt(topography[WORLD_TILE(0,y-1)]);
  105.         landtype_here=landtype_up;
  106.         if (random(100)>=CHANCE_LAND_GROUPING) /* NO GROUPING */
  107.         {
  108.             if (random(100)>=world_type) landtype_here=1;
  109.             else landtype_here=0;
  110.         }
  111.  
  112.         if (landtype_here==0) topography[WORLD_TILE(0,y)]=
  113.             random (NUM_GRASS_TILES)+FIRST_GRASS_TILE;   /* GRASS */
  114.         else topography[WORLD_TILE(0,y)]=
  115.             random (NUM_DIRT_TILES)+FIRST_DIRT_TILE;     /* DIRT */
  116.     }
  117.  
  118.     /* DO SUBSEQUENT ROWS */
  119.     for (y=1; y<WORLD_HEIGHT; y++)
  120.     for (x=1; x<WORLD_WIDTH; x++)
  121.     {
  122.         landtype_left=isdirt(topography[WORLD_TILE(x-1,y)]);
  123.         landtype_up=isdirt(topography[WORLD_TILE(x,y-1)]);
  124.         landtype_here=landtype_left;
  125.  
  126.         if (random(100)>=CHANCE_LAND_GROUPING) /* UNGROUP */
  127.         {
  128.             if (random(100)>=world_type) landtype_here=1;
  129.             else landtype_here=0;
  130.         }
  131.         else if (random(2)) landtype_here=landtype_up;
  132.  
  133.         if (landtype_here==0) topography[WORLD_TILE(x,y)]=
  134.             random (NUM_GRASS_TILES)+FIRST_GRASS_TILE;   /* GRASS */
  135.         else topography[WORLD_TILE(x,y)]=
  136.             random (NUM_DIRT_TILES)+FIRST_DIRT_TILE;     /* DIRT */
  137.     }
  138.  
  139.     if (edgemode) add_dirt_edges ();
  140. }
  141.  
  142. /*
  143.  *
  144.  * Initializes background and foreground tile lists.
  145.  *
  146.  */
  147. void init_world(void)
  148. {
  149.     init_background();
  150.     init_foreground();
  151.     view_x=random(WORLD_WIDTH-VIEW_WIDTH);
  152.     view_y=random(WORLD_HEIGHT-VIEW_HEIGHT);
  153. }
  154.